﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LdCms.Web.Controllers.API.Member.V1
{
    using LdCms.Common.Extension;
    using LdCms.Common.Utility;

    /// <summary>
    /// 会员积分接口：
    ///     1、获取会员积分列表-(分页)
    ///        GET：cgi-bin/v2/member/point/list?access_token=access_token&page=1&count=10
    ///        
    ///         
    /// 
    /// 
    /// 
    /// </summary>
    public partial class MemberController : BaseApiController
    {
        /// <summary>
        /// 获取会员积分列表-分页
        /// </summary>
        /// <param name="access_token"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("point/list")]
        public IActionResult GetPointRecord(string access_token)
        {
            long logId = 0;
            try
            {
                logId = BaseApiManager.SaveLogs(access_token);
                string companyId = MemberAccount.CompanyID;
                string memberId = MemberAccount.MemberID;
                int page = Utility.IsNum(GetQueryString("page"), 1);
                int count = Utility.IsNum(GetQueryString("count"), 10);
                int pageId = Utility.ToPageIndex(page);
                int pageSize = Utility.ToPageCount(count);
                int total = PointRecordService.CountPointRecord(SystemID, companyId, memberId);
                var lists = PointRecordService.GetPointRecordPagingByMemberId(SystemID, companyId, memberId, pageId, pageSize);
                var data = from m in lists
                           select new
                           {
                               type = m.TypeID,
                               type_name = m.TypeName,
                               points = m.Points,
                               tasks_id = m.TasksID.IIF(),
                               body = m.Body.IIF(),
                               remark = m.Remark.IIF(),
                               date = m.CreateDate
                           };
                return Success(logId, "ok", new { page, total, rows = data });


            }
            catch (Exception ex)
            {
                return Error(logId, ex.Message);
            }
        }


    }
}